home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1998 November: Tool Chest / Dev.CD Nov 98 TC.toast / Sample Code / Snippets / Sound / Cheap Studio / _source / Cheap_Studio.c next >
Encoding:
C/C++ Source or Header  |  1996-11-15  |  21.4 KB  |  731 lines  |  [TEXT/CWIE]

  1. /*
  2. **    Apple Macintosh Developer Technical Support
  3. **
  4. **    Routines demonstrating how to play and record sound at the same time.
  5. **
  6. **    by Mark Cookson, Apple Developer Technical Support
  7. **
  8. **    File:    Cheap_Studio.c
  9. **
  10. **    Copyright ©1996 Apple Computer, Inc.
  11. **    All rights reserved.
  12. **
  13. **    You may incorporate this sample code into your applications without
  14. **    restriction, though the sample code has been provided "AS IS" and the
  15. **    responsibility for its operation is 100% yours.  However, what you are
  16. **    not permitted to do is to redistribute the source as "Apple Sample
  17. **    Code" after having made changes. If you're going to re-distribute the
  18. **    source, we require that you make it clear in the source that the code
  19. **    was descended from Apple Sample Code, but that you've made changes.
  20. */
  21.  
  22. #include "SimpleApp_Sound.h"
  23. #include <SoundInput.h>
  24. #include <Drag.h>
  25. #include <Gestalt.h>
  26.  
  27. typedef struct {
  28.         long            sanitycheck;
  29.         SPBPtr            recordRec;
  30.         Ptr                pb0,
  31.                         pb1;
  32.         Ptr                recBuffer0,
  33.                         recBuffer1;
  34.         Fixed            sampleRate;
  35.         OSType            compression;
  36.         unsigned long    totalBytes;
  37.         long            myA5,
  38.                         devBuffer,
  39.                         soundRefNum;
  40.         short            whichBuffer,
  41.                         fileRefNum,
  42.                         numChannels,
  43.                         sampleSize;
  44.         OSErr            theErr;        //last error returned by SPBRecord or PBWrite
  45. } Vars, *VarsPtr;
  46.  
  47. OSErr    PrepairToRecordToDisk (VarsPtr myVars);
  48. OSErr    RecordToDisk (VarsPtr);
  49. OSErr    FinishRecording (VarsPtr myVars);
  50.  
  51. Vars                myVars;
  52.  
  53. /*-----------------------------------------------------------------------*/
  54.         void    MyIdleProc (EventRecord *evt)
  55. /*-----------------------------------------------------------------------*/
  56. {
  57. #ifndef __SC__
  58. #pragma unused (evt)
  59. #endif
  60.  
  61.     if (sound1Playing && ASoundIsDone (mySoundInfo1) == true) {
  62.         ASoundDonePlaying (mySoundInfo1, nil);
  63.         gSACurControl = playButton1;
  64.         sound1Playing = false;
  65.         SetMyTitle ("\pPlay");
  66.     }
  67.     if (sound2Playing && ASoundIsDone (mySoundInfo2) == true) {
  68.         ASoundDonePlaying (mySoundInfo2, nil);
  69.         gSACurControl = playButton2;
  70.         sound2Playing = false;
  71.         SetMyTitle ("\pPlay");
  72.     }
  73.     if (sound3Playing && ASoundIsDone (mySoundInfo3) == true) {
  74.         ASoundDonePlaying (mySoundInfo3, nil);
  75.         gSACurControl = playButton3;
  76.         sound3Playing = false;
  77.         SetMyTitle ("\pPlay");
  78.     }
  79.     if (sound4Playing && ASoundIsDone (mySoundInfo4) == true) {
  80.         ASoundDonePlaying (mySoundInfo4, nil);
  81.         gSACurControl = playButton4;
  82.         sound4Playing = false;
  83.         SetMyTitle ("\pPlay");
  84.     }
  85.     if (sound5Playing && ASoundIsDone (mySoundInfo5) == true) {
  86.         ASoundDonePlaying (mySoundInfo5, nil);
  87.         gSACurControl = playButton5;
  88.         sound5Playing = false;
  89.         SetMyTitle ("\pPlay");
  90.     }
  91.     if (sound6Playing && ASoundIsDone (mySoundInfo6) == true) {
  92.         ASoundDonePlaying (mySoundInfo6, nil);
  93.         gSACurControl = playButton6;
  94.         sound6Playing = false;
  95.         SetMyTitle ("\pPlay");
  96.     }
  97.     if (playAll == true) {
  98.         if (!sound1Playing && !sound2Playing && !sound3Playing && !sound4Playing && !sound5Playing && !sound6Playing) {
  99.             gSACurControl = playAllButton;
  100.             SetMyTitle ("\pPlay All");
  101.             playAll = false;
  102.         }
  103.     } else {
  104.         if (sound1Playing && sound2Playing && sound3Playing && sound4Playing && sound5Playing && sound6Playing) {
  105.             gSACurControl = playAllButton;
  106.             SetMyTitle ("\pStop All");
  107.             playAll = true;
  108.         }
  109.     }
  110. }
  111.  
  112. /*-----------------------------------------------------------------------*/
  113.         OSErr    DoPlay1 (void)
  114. /*-----------------------------------------------------------------------*/
  115. {
  116.     OSErr    theErr;
  117.  
  118.     if (sound1Set == false) {
  119.         theErr = ASoundGetFileToPlay (mySoundInfo1);
  120.         theErr = ASoundReadyForPlaying (mySoundInfo1, nil);
  121.         if (theErr == noErr) {
  122.             sound1Set = true;
  123.             sound1Playing = false;
  124.             SetMyTitle ("\pPlay");
  125.         }
  126.     } else {
  127.         if (sound1Playing == false) {
  128.             if (playAll == true) {
  129.                 SndCommand    theCmd;
  130.                 SndChannelPtr    theChan;
  131.  
  132.                 theChan = ASoundGetChan (mySoundInfo1);
  133.                 theCmd.cmd = syncCmd;
  134.                 theCmd.param1 = soundsToSync;
  135.                 theCmd.param2 = 'scme';
  136.                 theErr = SndDoImmediate (theChan, &theCmd);
  137.             }
  138.             theErr = ASoundPlay (mySoundInfo1);
  139.             if (theErr == noErr) {
  140.                 sound1Playing = true;
  141.                 gSACurControl = playButton1;
  142.                 SetMyTitle ("\pStop");
  143.             }
  144.         } else {
  145.             theErr = ASoundStop (mySoundInfo1);
  146.         }
  147.     }
  148.  
  149.     return theErr;
  150. }
  151.  
  152. /*-----------------------------------------------------------------------*/
  153.         OSErr    DoPlay2 (void)
  154. /*-----------------------------------------------------------------------*/
  155. {
  156.     OSErr    theErr;
  157.  
  158.     if (sound2Set == false) {
  159.         theErr = ASoundGetFileToPlay (mySoundInfo2);
  160.         theErr = ASoundReadyForPlaying (mySoundInfo2, nil);
  161.         if (theErr == noErr) {
  162.             sound2Set = true;
  163.             sound2Playing = false;
  164.             SetMyTitle ("\pPlay");
  165.         }
  166.     } else {
  167.         if (sound2Playing == false) {
  168.             if (playAll == true) {
  169.                 SndCommand    theCmd;
  170.                 SndChannelPtr    theChan;
  171.  
  172.                 theChan = ASoundGetChan (mySoundInfo2);
  173.                 theCmd.cmd = syncCmd;
  174.                 theCmd.param1 = soundsToSync;
  175.                 theCmd.param2 = 'scme';
  176.                 theErr = SndDoImmediate (theChan, &theCmd);
  177.             }
  178.             theErr = ASoundPlay (mySoundInfo2);
  179.             if (theErr == noErr) {
  180.                 sound2Playing = true;
  181.                 gSACurControl = playButton2;
  182.                 SetMyTitle ("\pStop");
  183.             }
  184.         } else {
  185.             theErr = ASoundStop (mySoundInfo2);
  186.         }
  187.     }
  188.  
  189.     return theErr;
  190. }
  191.  
  192. /*-----------------------------------------------------------------------*/
  193.         OSErr    DoPlay3 (void)
  194. /*-----------------------------------------------------------------------*/
  195. {
  196.     OSErr    theErr;
  197.  
  198.     if (sound3Set == false) {
  199.         theErr = ASoundGetFileToPlay (mySoundInfo3);
  200.         theErr = ASoundReadyForPlaying (mySoundInfo3, nil);
  201.         if (theErr == noErr) {
  202.             sound3Set = true;
  203.             sound3Playing = false;
  204.             SetMyTitle ("\pPlay");
  205.         }
  206.     } else {
  207.         if (sound3Playing == false) {
  208.             if (playAll == true) {
  209.                 SndCommand    theCmd;
  210.                 SndChannelPtr    theChan;
  211.  
  212.                 theChan = ASoundGetChan (mySoundInfo3);
  213.                 theCmd.cmd = syncCmd;
  214.                 theCmd.param1 = soundsToSync;
  215.                 theCmd.param2 = 'scme';
  216.                 theErr = SndDoImmediate (theChan, &theCmd);
  217.             }
  218.             theErr = ASoundPlay (mySoundInfo3);
  219.             if (theErr == noErr) {
  220.                 sound3Playing = true;
  221.                 gSACurControl = playButton3;
  222.                 SetMyTitle ("\pStop");
  223.             }
  224.         } else {
  225.             theErr = ASoundStop (mySoundInfo3);
  226.         }
  227.     }
  228.  
  229.     return theErr;
  230. }
  231.  
  232. /*-----------------------------------------------------------------------*/
  233.         OSErr    DoPlay4 (void)
  234. /*-----------------------------------------------------------------------*/
  235. {
  236.     OSErr    theErr;
  237.  
  238.     if (sound4Set == false) {
  239.         theErr = ASoundGetFileToPlay (mySoundInfo4);
  240.         theErr = ASoundReadyForPlaying (mySoundInfo4, nil);
  241.         if (theErr == noErr) {
  242.             sound4Set = true;
  243.             sound4Playing = false;
  244.             SetMyTitle ("\pPlay");
  245.         }
  246.     } else {
  247.         if (sound4Playing == false) {
  248.             if (playAll == true) {
  249.                 SndCommand    theCmd;
  250.                 SndChannelPtr    theChan;
  251.  
  252.                 theChan = ASoundGetChan (mySoundInfo4);
  253.                 theCmd.cmd = syncCmd;
  254.                 theCmd.param1 = soundsToSync;
  255.                 theCmd.param2 = 'scme';
  256.                 theErr = SndDoImmediate (theChan, &theCmd);
  257.             }
  258.             theErr = ASoundPlay (mySoundInfo4);
  259.             if (theErr == noErr) {
  260.                 sound4Playing = true;
  261.                 gSACurControl = playButton4;
  262.                 SetMyTitle ("\pStop");
  263.             }
  264.         } else {
  265.             theErr = ASoundStop (mySoundInfo4);
  266.         }
  267.     }
  268.  
  269.     return theErr;
  270. }
  271.  
  272. /*-----------------------------------------------------------------------*/
  273.         OSErr    DoPlay5 (void)
  274. /*-----------------------------------------------------------------------*/
  275. {
  276.     OSErr    theErr;
  277.  
  278.     if (sound5Set == false) {
  279.         theErr = ASoundGetFileToPlay (mySoundInfo5);
  280.         theErr = ASoundReadyForPlaying (mySoundInfo5, nil);
  281.         if (theErr == noErr) {
  282.             sound5Set = true;
  283.             sound5Playing = false;
  284.             SetMyTitle ("\pPlay");
  285.         }
  286.     } else {
  287.         if (sound5Playing == false) {
  288.             if (playAll == true) {
  289.                 SndCommand    theCmd;
  290.                 SndChannelPtr    theChan;
  291.  
  292.                 theChan = ASoundGetChan (mySoundInfo5);
  293.                 theCmd.cmd = syncCmd;
  294.                 theCmd.param1 = soundsToSync;
  295.                 theCmd.param2 = 'scme';
  296.                 theErr = SndDoImmediate (theChan, &theCmd);
  297.             }
  298.             theErr = ASoundPlay (mySoundInfo5);
  299.             if (theErr == noErr) {
  300.                 sound5Playing = true;
  301.                 gSACurControl = playButton5;
  302.                 SetMyTitle ("\pStop");
  303.             }
  304.         } else {
  305.             theErr = ASoundStop (mySoundInfo5);
  306.         }
  307.     }
  308.  
  309.     return theErr;
  310. }
  311.  
  312. /*-----------------------------------------------------------------------*/
  313.         OSErr    DoPlay6 (void)
  314. /*-----------------------------------------------------------------------*/
  315. {
  316.     OSErr    theErr;
  317.  
  318.     if (sound6Set == false) {
  319.         theErr = ASoundGetFileToPlay (mySoundInfo6);
  320.         theErr = ASoundReadyForPlaying (mySoundInfo6, nil);
  321.         if (theErr == noErr) {
  322.             sound6Set = true;
  323.             sound6Playing = false;
  324.             SetMyTitle ("\pPlay");
  325.         }
  326.     } else {
  327.         if (sound6Playing == false) {
  328.             if (playAll == true) {
  329.                 SndCommand    theCmd;
  330.                 SndChannelPtr    theChan;
  331.  
  332.                 theChan = ASoundGetChan (mySoundInfo6);
  333.                 theCmd.cmd = syncCmd;
  334.                 theCmd.param1 = soundsToSync;
  335.                 theCmd.param2 = 'scme';
  336.                 theErr = SndDoImmediate (theChan, &theCmd);
  337.             }
  338.             theErr = ASoundPlay (mySoundInfo6);
  339.             if (theErr == noErr) {
  340.                 sound6Playing = true;
  341.                 gSACurControl = playButton6;
  342.                 SetMyTitle ("\pStop");
  343.             }
  344.         } else {
  345.             theErr = ASoundStop (mySoundInfo6);
  346.         }
  347.     }
  348.  
  349.     return theErr;
  350. }
  351.  
  352. /*-----------------------------------------------------------------------*/
  353.         OSErr    DoPlayAll (void)
  354. /*-----------------------------------------------------------------------*/
  355. {
  356.     OSErr    theErr;
  357.  
  358.     if (playAll == false) {
  359.         playAll = true;
  360.         soundsToSync = 0;
  361.         if (sound1Set) soundsToSync++;
  362.         if (sound2Set) soundsToSync++;
  363.         if (sound3Set) soundsToSync++;
  364.         if (sound4Set) soundsToSync++;
  365.         if (sound5Set) soundsToSync++;
  366.         if (sound6Set) soundsToSync++;
  367.         if (sound1Set == true && sound1Playing == false) { theErr = DoPlay1 ();soundsToSync--;}
  368.         if (sound2Set == true && sound2Playing == false) { theErr = DoPlay2 ();soundsToSync--;}
  369.         if (sound3Set == true && sound3Playing == false) { theErr = DoPlay3 ();soundsToSync--;}
  370.         if (sound4Set == true && sound4Playing == false) { theErr = DoPlay4 ();soundsToSync--;}
  371.         if (sound5Set == true && sound5Playing == false) { theErr = DoPlay5 ();soundsToSync--;}
  372.         if (sound6Set == true && sound6Playing == false) { theErr = DoPlay6 ();}
  373.         gSACurControl = playAllButton;
  374.         SetMyTitle ("\pStop All");
  375.     } else {
  376.         playAll = false;
  377.         if (sound1Set == true && sound1Playing == true) theErr = DoPlay1 ();
  378.         if (sound2Set == true && sound2Playing == true) theErr = DoPlay2 ();
  379.         if (sound3Set == true && sound3Playing == true) theErr = DoPlay3 ();
  380.         if (sound4Set == true && sound4Playing == true) theErr = DoPlay4 ();
  381.         if (sound5Set == true && sound5Playing == true) theErr = DoPlay5 ();
  382.         if (sound6Set == true && sound6Playing == true) theErr = DoPlay6 ();
  383.         gSACurControl = playAllButton;
  384.         SetMyTitle ("\pPlay All");
  385.     }
  386.  
  387.     return theErr;
  388. }
  389.  
  390. /*-----------------------------------------------------------------------*/
  391.         OSErr    DoRecord (void)
  392. /*-----------------------------------------------------------------------*/
  393. {
  394.     OSErr    theErr;
  395.  
  396.     if (!recording) {
  397.         if (!prepairedToRecord) {
  398.             theErr = PrepairToRecordToDisk (&myVars);
  399.             if (theErr == noErr) {
  400.                 prepairedToRecord = true;
  401.                 gSACurControl = recordButton;
  402.                 SetMyTitle ("\pRecord&Play");
  403.             }
  404.         } else {
  405.             DoPlayAll ();
  406.             theErr = RecordToDisk (&myVars);
  407.             recording = true;
  408.             gSACurControl = recordButton;
  409.             SetMyTitle ("\pStop record");
  410.         }
  411.     } else {
  412.         theErr = FinishRecording (&myVars);
  413.         recording = false;
  414.         DoPlayAll ();
  415.         prepairedToRecord = false;
  416.         gSACurControl = recordButton;
  417.         SetMyTitle ("\pSetup Rec");
  418.     }
  419.  
  420.     return theErr;
  421. }
  422.  
  423. /*-----------------------------------------------------------------------*/
  424.         OSErr    MuteSound1 (void)
  425. /*-----------------------------------------------------------------------*/
  426. {
  427.     OSErr    theErr;
  428.     unsigned short    leftVol, rightVol;
  429.  
  430.     SetControlValue (muteCheck1, !GetControlValue (muteCheck1));
  431.     theErr = ASoundGetVolume (mySoundInfo1, &leftVol, &rightVol);
  432.     if (leftVol != 0 || rightVol != 0) {
  433.         theErr = ASoundSetVolume (mySoundInfo1, 0, 0);
  434.     } else {
  435.         theErr = ASoundSetVolume (mySoundInfo1, 0x100, 0x100);
  436.     }
  437.  
  438.     return theErr;
  439. }
  440.  
  441. /*-----------------------------------------------------------------------*/
  442.         OSErr    MuteSound2 (void)
  443. /*-----------------------------------------------------------------------*/
  444. {
  445.     OSErr    theErr;
  446.     unsigned short    leftVol, rightVol;
  447.  
  448.     SetControlValue (muteCheck2, !GetControlValue (muteCheck2));
  449.     theErr = ASoundGetVolume (mySoundInfo2, &leftVol, &rightVol);
  450.     if (leftVol != 0 || rightVol != 0) {
  451.         theErr = ASoundSetVolume (mySoundInfo2, 0, 0);
  452.     } else {
  453.         theErr = ASoundSetVolume (mySoundInfo2, 0x100, 0x100);
  454.     }
  455.  
  456.     return theErr;
  457. }
  458.  
  459. /*-----------------------------------------------------------------------*/
  460.         OSErr    MuteSound3 (void)
  461. /*-----------------------------------------------------------------------*/
  462. {
  463.     OSErr    theErr;
  464.     unsigned short    leftVol, rightVol;
  465.  
  466.     SetControlValue (muteCheck3, !GetControlValue (muteCheck3));
  467.     theErr = ASoundGetVolume (mySoundInfo3, &leftVol, &rightVol);
  468.     if (leftVol != 0 || rightVol != 0) {
  469.         theErr = ASoundSetVolume (mySoundInfo3, 0, 0);
  470.     } else {
  471.         theErr = ASoundSetVolume (mySoundInfo3, 0x100, 0x100);
  472.     }
  473.  
  474.     return theErr;
  475. }
  476.  
  477. /*-----------------------------------------------------------------------*/
  478.         OSErr    MuteSound4 (void)
  479. /*-----------------------------------------------------------------------*/
  480. {
  481.     OSErr    theErr;
  482.     unsigned short    leftVol, rightVol;
  483.  
  484.     SetControlValue (muteCheck4, !GetControlValue (muteCheck4));
  485.     theErr = ASoundGetVolume (mySoundInfo4, &leftVol, &rightVol);
  486.     if (leftVol != 0 || rightVol != 0) {
  487.         theErr = ASoundSetVolume (mySoundInfo4, 0, 0);
  488.     } else {
  489.         theErr = ASoundSetVolume (mySoundInfo4, 0x100, 0x100);
  490.     }
  491.  
  492.     return theErr;
  493. }
  494.  
  495. /*-----------------------------------------------------------------------*/
  496.         OSErr    MuteSound5 (void)
  497. /*-----------------------------------------------------------------------*/
  498. {
  499.     OSErr    theErr;
  500.     unsigned short    leftVol, rightVol;
  501.  
  502.     SetControlValue (muteCheck5, !GetControlValue (muteCheck5));
  503.     theErr = ASoundGetVolume (mySoundInfo5, &leftVol, &rightVol);
  504.     if (leftVol != 0 || rightVol != 0) {
  505.         theErr = ASoundSetVolume (mySoundInfo5, 0, 0);
  506.     } else {
  507.         theErr = ASoundSetVolume (mySoundInfo5, 0x100, 0x100);
  508.     }
  509.  
  510.     return theErr;
  511. }
  512.  
  513. /*-----------------------------------------------------------------------*/
  514.         OSErr    MuteSound6 (void)
  515. /*-----------------------------------------------------------------------*/
  516. {
  517.     OSErr    theErr;
  518.     unsigned short    leftVol, rightVol;
  519.  
  520.     SetControlValue (muteCheck6, !GetControlValue (muteCheck6));
  521.     theErr = ASoundGetVolume (mySoundInfo6, &leftVol, &rightVol);
  522.     if (leftVol != 0 || rightVol != 0) {
  523.         theErr = ASoundSetVolume (mySoundInfo6, 0, 0);
  524.     } else {
  525.         theErr = ASoundSetVolume (mySoundInfo6, 0x100, 0x100);
  526.     }
  527.  
  528.     return theErr;
  529. }
  530.  
  531. pascal OSErr    ClearAllSounds (long menuResult)
  532. {
  533. #pragma unused (menuResult)
  534.     OSErr        err;
  535.  
  536.     mySoundInfo1 = ASoundNew (&err);
  537.     mySoundInfo2 = ASoundNew (&err);
  538.     mySoundInfo3 = ASoundNew (&err);
  539.     mySoundInfo4 = ASoundNew (&err);
  540.     mySoundInfo5 = ASoundNew (&err);
  541.     mySoundInfo6 = ASoundNew (&err);
  542.  
  543.     sound1Set = false;
  544.     sound2Set = false;
  545.     sound3Set = false;
  546.     sound4Set = false;
  547.     sound5Set = false;
  548.     sound6Set = false;
  549.  
  550.     gSACurControl = playButton1;
  551.     SetMyTitle ("\pLoad Sound 1");
  552.     gSACurControl = playButton2;
  553.     SetMyTitle ("\pLoad Sound 2");
  554.     gSACurControl = playButton3;
  555.     SetMyTitle ("\pLoad Sound 3");
  556.     gSACurControl = playButton4;
  557.     SetMyTitle ("\pLoad Sound 4");
  558.     gSACurControl = playButton5;
  559.     SetMyTitle ("\pLoad Sound 5");
  560.     gSACurControl = playButton6;
  561.     SetMyTitle ("\pLoad Sound 6");
  562.  
  563.     return err;
  564. }
  565.  
  566. /*-----------------------------------------------------------------------*/
  567.         void    main (void)
  568. /*-----------------------------------------------------------------------*/
  569. {
  570.     Rect    r;
  571.     long    soundAttr;
  572.     short    err;
  573.  
  574.     InitSimpleApp (2, kUseStandardMenu);          /* Simple App Sets up the Tool Box For us */
  575.     GetDocumentWindow (128);                     /* Get our stored window */
  576.  
  577.     SetRectLocation (&r, 10, 2);                /* This Sets a rects anchor point */
  578.     SetRectDimensions (&r, 90, 20);                /* This Sets its size without changing it position */
  579.     {
  580.         long buttonID = 1;
  581.         err = InstallPushButton (&buttonID, gSACurrentWindow, "\pLoad Sound 1", &r, (char)0, (ButtonHitProc) DoPlay1, (ButtonUpdateProc)nil);
  582.         playButton1 = gSACurControl;
  583.     }
  584.     
  585.     SetRectLocation (&r, 130, 2);                /* This Sets a rects anchor point */
  586.     SetRectDimensions (&r, 90, 20);                /* This Sets its size without changing it position */
  587.     {
  588.         long buttonID = 2; 
  589.         err = InstallPushButton (&buttonID, gSACurrentWindow, "\pLoad Sound 2", &r, (char)0, (ButtonHitProc) DoPlay2, (ButtonUpdateProc)nil);
  590.         playButton2 = gSACurControl;
  591.     }
  592.     
  593.     SetRectLocation (&r, 270, 2);                /* This Sets a rects anchor point */
  594.     SetRectDimensions (&r, 90, 20);                /* This Sets its size without changing it position */
  595.     {
  596.         long buttonID = 3;
  597.         err = InstallPushButton (&buttonID, gSACurrentWindow, "\pLoad Sound 3", &r, (char)0, (ButtonHitProc) DoPlay3, (ButtonUpdateProc)nil);
  598.         playButton3 = gSACurControl;
  599.     }
  600.  
  601.     SetRectLocation (&r, 10, 25);                /* This Sets a rects anchor point */
  602.     SetRectDimensions (&r, 90, 20);                /* This Sets its size without changing it position */
  603.     {
  604.         long buttonID = 4;
  605.         err = InstallPushButton (&buttonID, gSACurrentWindow, "\pLoad Sound 4", &r, (char)0, (ButtonHitProc) DoPlay4, (ButtonUpdateProc)nil);
  606.         playButton4 = gSACurControl;
  607.     }
  608.  
  609.     SetRectLocation (&r, 130, 25);                /* This Sets a rects anchor point */
  610.     SetRectDimensions (&r, 90, 20);                /* This Sets its size without changing it position */
  611.     {
  612.         long buttonID = 5;
  613.         err = InstallPushButton (&buttonID, gSACurrentWindow, "\pLoad Sound 5", &r, (char)0, (ButtonHitProc) DoPlay5, (ButtonUpdateProc)nil);
  614.         playButton5 = gSACurControl;
  615.     }
  616.  
  617.     SetRectLocation (&r, 270, 25);                /* This Sets a rects anchor point */
  618.     SetRectDimensions (&r, 90, 20);                /* This Sets its size without changing it position */
  619.     {
  620.         long buttonID = 6;
  621.         err = InstallPushButton (&buttonID, gSACurrentWindow, "\pLoad Sound 6", &r, (char)0, (ButtonHitProc) DoPlay6, (ButtonUpdateProc)nil);
  622.         playButton6 = gSACurControl;
  623.     }
  624.  
  625.     SetRectLocation (&r, 10, 50);                /* This Sets a rects anchor point */
  626.     SetRectDimensions (&r, 90, 20);                /* This Sets its size without changing it position */
  627.     {
  628.         long buttonID = 7;
  629.         err = InstallPushButton (&buttonID, gSACurrentWindow, "\pSetup Rec", &r, (char)0, (ButtonHitProc) DoRecord, (ButtonUpdateProc)nil);
  630.         recordButton = gSACurControl;
  631.     }
  632.  
  633.     SetRectLocation (&r, 110, 80);                /* This Sets a rects anchor point */
  634.     SetRectDimensions (&r, 90, 20);                /* This Sets its size without changing it position */
  635.     {
  636.         long buttonID = 8;
  637.         err = InstallPushButton (&buttonID, gSACurrentWindow, "\pPlay All", &r, (char)0, (ButtonHitProc) DoPlayAll, (ButtonUpdateProc)nil);
  638.         playAllButton = gSACurControl;
  639.     }
  640.  
  641.     SetRectLocation (&r, 110, 2);                /* This Sets a rects anchor point */
  642.     SetRectDimensions (&r, 90, 20);                /* This Sets its size without changing it position */
  643.     {
  644.         long buttonID = 9;
  645.         err = InstallCheckBox (&buttonID, gSACurrentWindow, "\p", &r , (char)0, 1, (ButtonHitProc) MuteSound1, (ButtonUpdateProc)nil);
  646.         muteCheck1 = gSACurControl;
  647.     }    
  648.  
  649.     SetRectLocation (&r, 250, 2);                /* This Sets a rects anchor point */
  650.     SetRectDimensions (&r, 90, 20);                /* This Sets its size without changing it position */
  651.     {
  652.         long buttonID = 10;
  653.         err = InstallCheckBox (&buttonID, gSACurrentWindow, "\p", &r , (char)0, 1, (ButtonHitProc) MuteSound2, (ButtonUpdateProc)nil);
  654.         muteCheck2 = gSACurControl;
  655.     }    
  656.  
  657.     SetRectLocation (&r, 370, 2);                /* This Sets a rects anchor point */
  658.     SetRectDimensions (&r, 90, 20);                /* This Sets its size without changing it position */
  659.     {
  660.         long buttonID = 11;
  661.         err = InstallCheckBox (&buttonID, gSACurrentWindow, "\p", &r , (char)0, 1, (ButtonHitProc) MuteSound3, (ButtonUpdateProc)nil);
  662.         muteCheck3 = gSACurControl;
  663.     }    
  664.  
  665.     SetRectLocation (&r, 110, 25);                /* This Sets a rects anchor point */
  666.     SetRectDimensions (&r, 90, 20);                /* This Sets its size without changing it position */
  667.     {
  668.         long buttonID = 12;
  669.         err = InstallCheckBox (&buttonID, gSACurrentWindow, "\p", &r , (char)0, 1, (ButtonHitProc) MuteSound4, (ButtonUpdateProc)nil);
  670.         muteCheck4 = gSACurControl;
  671.     }    
  672.  
  673.     SetRectLocation (&r, 250, 25);                /* This Sets a rects anchor point */
  674.     SetRectDimensions (&r, 90, 20);                /* This Sets its size without changing it position */
  675.     {
  676.         long buttonID = 13;
  677.         err = InstallCheckBox (&buttonID, gSACurrentWindow, "\p", &r , (char)0, 1, (ButtonHitProc) MuteSound5, (ButtonUpdateProc)nil);
  678.         muteCheck5 = gSACurControl;
  679.     }    
  680.  
  681.     SetRectLocation (&r, 370, 25);                /* This Sets a rects anchor point */
  682.     SetRectDimensions (&r, 90, 20);                /* This Sets its size without changing it position */
  683.     {
  684.         long buttonID = 14;
  685.         err = InstallCheckBox (&buttonID, gSACurrentWindow, "\p", &r , (char)0, 1, (ButtonHitProc) MuteSound6, (ButtonUpdateProc)nil);
  686.         muteCheck6 = gSACurControl;
  687.     }    
  688.  
  689.     mySoundInfo1 = ASoundNew (&err);
  690.     if (err == noErr)
  691.         mySoundInfo2 = ASoundNew (&err);
  692.     if (err == noErr)
  693.         mySoundInfo3 = ASoundNew (&err);
  694.     if (err == noErr)
  695.         mySoundInfo4 = ASoundNew (&err);
  696.     if (err == noErr)
  697.         mySoundInfo5 = ASoundNew (&err);
  698.     if (err == noErr)
  699.         mySoundInfo6 = ASoundNew (&err);
  700.  
  701.     InstallMenuItem (130, 9, "\pClear all sounds", 0, 'R', ClearAllSounds, nil);
  702.     InstallIdleProc ((EventProcs)MyIdleProc);
  703.  
  704.     err = Gestalt (gestaltSoundAttr, &soundAttr);
  705.     if ((soundAttr & (1 << gestaltPlayAndRecord)) == false) {
  706.         DebugStr ("\pCan't play and record simultaniously.");
  707.     }
  708.  
  709.     if (err == noErr)
  710.         Run ();                                 /* Let SimpleApp handle the rest */
  711. }
  712.  
  713. // utility functions since I already keep the control handle around
  714. /*-----------------------------------------------------------------------*/
  715.     void EnableControl (ControlRef cr)
  716. /*-----------------------------------------------------------------------*/
  717. {
  718.     if (cr != nil) {
  719.         HiliteControl(cr, nil);
  720.     }
  721. }
  722.  
  723. /*-----------------------------------------------------------------------*/
  724.     void DisableControl (ControlRef cr)
  725. /*-----------------------------------------------------------------------*/
  726. {
  727.     if (cr != nil) {
  728.         HiliteControl(cr, 255);
  729.     }
  730. }
  731.